Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Postgres (+ Redshift) batch exports now async #18631

Merged

Conversation

tomasfarias
Copy link
Contributor

@tomasfarias tomasfarias commented Nov 14, 2023

Problem

Making PG batch exports async means less blocking the main thread, more concurrent tasks, more performance! Let's do all destinations async and bring down the number of required workers!

Turns out is quite easy to make Postgres batch exports async. What's more, the new COPY API doesn't require a file, so we may try a different buffered approach in the future. I'm very excited for the future of batch exports!

Changes

  • Add psycopg dependency
  • Replace psycopg2 for psycopg everywhere.
  • Sprinkle in async and await.
  • The only user-facing change is that ip and site url are now "" instead of None, but I don't think that's very significant: at least semantically we are not losing or gaining anything as these fields are meant to be deprecated, and in terms of schema both are compatible.

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

How did you test this code?

Same tests as before, just now async too.
Also added redshift tests that target local postgres db instance. Since postgres is fairly compatible with Redshift, having automated tests is better than nothing (of course, tests can still be run against a real Redshift instance).

@tomasfarias tomasfarias force-pushed the refactor/async-postgres-and-redshift-batch-exports branch from 5f78c22 to ee69926 Compare November 14, 2023 23:30
@tomasfarias tomasfarias marked this pull request as ready for review November 15, 2023 08:55
@tomasfarias
Copy link
Contributor Author

Going to merge this as the Redshift code includes a bugfix that we need to migrate folks over from export apps.

@tomasfarias tomasfarias merged commit 70970ff into master Nov 15, 2023
68 checks passed
@tomasfarias tomasfarias deleted the refactor/async-postgres-and-redshift-batch-exports branch November 15, 2023 08:56
pauldambra pushed a commit that referenced this pull request Nov 15, 2023
* refactor: Postgres batch exports now async

* fix: Let's use from psycopg import sql instead

* test: Update Redshift tests

* fix: Typing issues

* fix: Main insert batch loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant